<template>
	<view class="content">
		<view scroll-y="true" class="edit-content">
			<view class="uni-list-cell" hover-class="uni-list-cell-hover">
				<!-- <view class="uni-list-cell-navigate uni-navigate-right"> -->
				<view class="uni-list-cell-navigate">
					<text>日期</text>
					<!-- <picker class="picker" mode="date" :value="formData.log_date" :start="startDate" :end="endDate" @change="bindDateChange">
						<view class="uni-input">{{formData.log_date}}{{log_week}}</view>
					</picker> -->
					<view>
						{{formData.log_date}} {{log_week}}
					</view>
				</view>
			</view>
			<!-- 	<view class="uni-list-cell" hover-class="uni-list-cell-hover" @click="showImplement()">
				<view class="uni-list-cell-navigate uni-navigate-right">
					<text>实施部位</text>
					<text class="right-text">{{project_part_name}}</text>
				</view>
			</view>
			<uni-popup type="middle" :show="showImplementModal" @hidePopup="hidePopup" :popupWidth="600">
				<view class="task-comment-popup-title">实施部位选择</view>
				<view class="task-comment-popup-note">
					<view class="task-comment-popup-list">
						<view class="list-row" v-for="list in implementDatas" :key='list.key'>
							<view class="uni-input implement-text" @click="showSpacePicker(list.key)">{{list.space_name}}</view>
							<view class="uni-input implement-text" @click="showPartPicker(list.key,list.spaceId)">{{list.part_name}}</view>
							<button type="default" @click="removeImplement(list.key)">x</button>
						</view>
					</view>
					<button class="mini-btn" type="default" size="mini" @click="addImplement">+ 添加</button>
				</view>
				<view>
					<button type="primary" @click="submitImplement">确定</button>
				</view>
			</uni-popup> -->
			<!-- 实施的空间 -->
			<!-- <mpvue-picker ref="mpvueSpaceRef" :deepLength="1" @onConfirm="onSpaceConfirm" :pickerValueArray="spaceArray"></mpvue-picker> -->
			<!-- 实施的部位 -->
			<!-- <mpvue-picker ref="mpvuePartRef" :deepLength="1" @onConfirm="onPartConfirm" :pickerValueArray="partArray"></mpvue-picker> -->
			<view class="uni-list-cell" hover-class="uni-list-cell-hover">
				<view class="uni-list-cell-navigate">
					<text>天气状况</text>
					<input class="right-text" v-model="formData.weather_situation" />
				</view>
			</view>

			<view class="uni-list-cell" hover-class="uni-list-cell-hover" @click="showConstruction()">
				<view class="uni-list-cell-navigate uni-navigate-right">
					<text>施工项</text>
					<text class="right-text">{{construction}}</text>
				</view>
			</view>
			<mpvue-picker ref="mpvueConstructionRef" :deepLength="1" @onConfirm="onConstructionConfirm" @onCancel="onConstructionCancel"
			 :pickerValueArray="constructionArray"></mpvue-picker>

			<view class="uni-list-cell" hover-class="uni-list-cell-hover" @click="showAttendance()">
				<view class="uni-list-cell-navigate uni-navigate-right">
					<text>出勤情况</text>
					<text class="right-text" style="flex: 2;">{{formData.attendance_situation?formData.attendance_situation:'出勤人数0人'}}</text>
				</view>
			</view>
			<uni-popup type="middle" :show="showAttendanceModal" @hidePopup="hidePopup" :popupWidth="600">
				<view class="task-comment-popup-title">出勤情况选择</view>
				<view class="task-comment-popup-note">
					<view class="task-comment-popup-list">
						<view class="list-row" v-for="list in formData.log_lines" :key='list.key'>
							<view class="uni-input implement-text" @click="showTypePicker(list.key)">{{list.name}}</view>
							<input class="uni-input implement-text" type="number" placeholder="几人" v-if="list.type!=='principals'" :value="list.labour_qty"
							 @input="attendanceInputNumber" @focus="attendanceInputFocus(list.key)" />
							<view class="uni-input implement-text text" @click="showPersonPicker(list.key)" v-if="list.type==='principals'">
								<text v-for="item in list.principal_info" :key="item.value">
									{{item.label}},
								</text>
							</view>
							<button @click="removeAttendance(list.key)">x</button>
						</view>
					</view>
					<button class="mini-btn" type="default" size="mini" @click="addAttendance()">+ 添加</button>
				</view>
				<view>
					<button type="primary" @click="submitAttendance">确定</button>
				</view>
			</uni-popup>
			<!-- 工作类型 -->
			<mpvue-picker ref="mpvueTypeRef" :deepLength="1" @onConfirm="onTypeConfirm" :pickerValueArray="typeArray"></mpvue-picker>
			<!-- 负责人 -->
			<mpvue-picker ref="mpvuePersonRef" :deepLength="1" @onConfirm="onPersonConfirm" @onCancel="onPersonConCancel"
			 :pickerValueArray="personArray"></mpvue-picker>
			<view class="uni-list-cell" hover-class="uni-list-cell-hover" @click="showProruptionPicker()">
				<view class="uni-list-cell-navigate uni-navigate-right">
					<text>突发事件</text>
					<text class="right-text">{{formData.is_emergency?'有':'无'}}</text>
				</view>
			</view>
			<mpvue-picker ref="mpvueProruptionRef" :deepLength="1" @onConfirm="onProruptionConfirm" @onCancel='onProruptionCancel'
			 :pickerValueArray="proruptionArray"></mpvue-picker>
			<view class="uni-list-cell" hover-class="uni-list-cell-hover">
				<view class="uni-list-cell-navigate" :style="{display:formData.is_emergency?'block':'none'}">
					<textarea v-show="!showAttendanceModal" placeholder="请描述突发事件" v-model="formData.emergency_note" maxlength="-1" auto-height></textarea>
				</view>
			</view>
			<view class="uni-list-cell-navigate">
				<text>施工记录：</text>
			</view>
			<view class="uni-list-cell" hover-class="uni-list-cell-hover">
				<view class="uni-list-cell-navigate">
					<textarea v-show="!showAttendanceModal&&isShow" placeholder="请描述施工情况+成品保护情况" v-model="formData.log_note" maxlength="-1" auto-height></textarea>
				</view>
			</view>
			<view class="cus-img-video">
				<cus-upload-image removeMark :imageList="formData.picture_data" :imgSize="200"></cus-upload-image>
				<cus-upload-video :src="formData.mediaurl" @success="videoSuccess"></cus-upload-video>
			</view>
			<view>
				<button class="btn-primary" type="primary" @click="submit">保存</button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		proruptionArray
	} from '../../../common/stateData.js'
	export default {
		data() {
			return {
				isAdd: true, //是编辑还是新增（true是新增，false是编辑）
				log_week: '', //施工星期
				imageList: [], //图片列表
				proruptionArray: proruptionArray, //突发情况选择器数据
				showTextarea: false,
				isShow: true,
				///---实施部位---///
				// showImplementModal: false, //实施部位模态框是否显示
				// implementArray: [], //实施部位选择器数据
				// implementIndex: 0, //索引用
				// implementDatas: [], //选中的施工部位数据
				// spaceArray: [], //空间选择器数据
				// partArrayList: [], //部位选择器数所有的数据
				// partArray: [], //部位选择器数据
				// implementKey: '', //当前点击的实施选择器是implementDatas中的哪一行
				// project_part_name: [], //拼合成的施工部位名称
				///-----施工项-----///
				constructionArray: [], //施工项的选择器数据
				construction: [],
				///---出勤情况---///
				showAttendanceModal: false, //出勤情况模态框是否显示
				attendanceArray: [], //出勤情况选择器数据
				attendanceIndex: 0, //索引用
				typeArray: [], //工作类型选择器数据
				personArray: [], //负责人选择器数据
				attendancekey: '', //当前点击的出勤情况选择器是formData.log_lines中的哪一行				
				formData: {
					hard_id: null, //项目id
					log_lines: [], //出勤情况具体数据
					is_emergency: false, //是否有突发事件
					weather_situation: '', //天气状况
					mediaurl: '',
					picture_data: [],
					process_ids: []
				},
				isFromMain: false, //是否是从主入口进来的
			}
		},
		onLoad(param) {
			this.formData.hard_id = parseInt(param.hard_id)
			this.getConstruction() //获取施工项
			// this.getSpace() //获取实施部位
			this.getType() //获取出勤情况
			if (param.log_id) {
				//是编辑页面
				this.isAdd = false
				this.getListDetail(param.log_id) //获取详情列表
			} else {
				//是新增页面
				this.isAdd = true
				uni.setNavigationBarTitle({
					title: "施工日志新增"
				})
				this.getWeather() //获取天气信息
				this.formData.log_date = param.date //带过来的日期
				this.log_week = this.getWeek(param.date) //加转换星期
				// for (let i = 0; i < 2; i++) {
				// 	// this.addImplement() //默认增加两行实施部位
				// 	this.addAttendance() //默认增加两行出勤情况
				// }
				for (let i = 0; i < 1; i++) {
					this.addAttendance() //默认增加一行出勤情况
				}
			}
			if (param.isFromMain) { //页面是从主入口进来的
				this.isFromMain = true
			} else {
				this.isFromMain = false
			}
		},
		methods: {
			videoSuccess(path) { // 视频上传成功返回路径
				this.formData.mediaurl = path
			},
			//编辑页面，获取详情
			getListDetail(log_id) {
				uni.showLoading({
					title: '',
					mask: false
				});
				uni.request({
					url: this.$store.state.baseUrl + '/lwj/app_project_log_info',
					method: 'POST',
					header: {
						token: this.$store.state.token
					},
					data: {
						log_id
					},
					success: res => {
						if (res.data.code === 1) {
							const info = res.data.data.info
							this.formData = {
								hard_id: this.formData.hard_id,
								log_id: info.id, //日志id
								// project_part: [], //施工部位
								weather_situation: info.weather_situation, //天气状况
								process_ids: [], //施工项
								attendance_situation: info.attendance_situation, //出勤情况
								log_lines: info.attendance_info, //出勤情况具体数据
								is_emergency: info.is_emergency, //是否有突发事件
								emergency_note: info.emergency_note, //突发事件详细
								log_date: info.log_date, //施工日期
								log_note: info.log_note, //施工情况记录
								picture_data: info.picture_data, //图片
								mediaurl: info.mediaurl // 视频地址
							}
							info.process_info.map((item) => {
								this.formData.process_ids.push(item.id)
							})
							this.construction = info.process_name !== '' ? info.process_name : []
							this.log_week = this.getWeek(info.log_date) //将日期转换成星期
							// this.project_part_name = info.position_name
							// info.position_info.map((item, index) => {
							// 	this.formData.project_part.push(item.id)
							// })
							// const implementList = info.position_info //施工部位详细信息
							// implementList.map((item, index) => {
							// 	this.implementDatas.push({
							// 		key: `NEW_TEMP_IP_${this.implementIndex}`,
							// 		space_name: item.space_name,
							// 		spaceId: item.parent_id,
							// 		part_name: item.part_name,
							// 		partId: item.id
							// 	})
							// 	this.implementIndex += 1
							// })
							for (let i = 0; i < this.formData.log_lines.length; i++) {
								this.formData.log_lines[i].key = `NEW_TEMP_IP_${this.attendanceIndex}`
								this.attendanceIndex += 1
								///给后台拼principal_ids
								let list = []
								if (this.formData.log_lines[i].type === 'principals' && this.formData.log_lines[i].principal_info) {
									this.formData.log_lines[i].principal_info.map((item, index) => {
										list.push(item.value)
									})
								}
								this.formData.log_lines[i].principal_ids = list
							}
							if (this.formData.log_lines) {
								this.formData.log_lines.sort(this.compare)
							}
							uni.hideLoading()
						}
					}
				});
			},
			//对出勤情况数据进行排序,让负责人在第一位
			compare(val1, val2) {
				if (val1.type > val2.type) {
					return 1;
				} else {
					return 0
				}
			},
			//转换成星期几
			getWeek(date) {
				return "星期" + "日一二三四五六".charAt(new Date(date).getDay())
			},
			//创建时候需要获取天气预报
			getWeather() {
				uni.getLocation({
					type: 'wgs84',
					success: (res) => {
						uni.request({
							url: this.$store.state.baseUrl + '/lwj/area_weather',
							method: 'POST',
							header: {
								token: this.$store.state.token
							},
							data: {
								code: res.longitude + "," + res.latitude
							},
							success: res => {
								if (res.data.code === 1) {
									this.formData.weather_situation = res.data.data[0].weather + ',气温' + res.data.data[0].temperature + "°C"
								}
							}
						});
					}
				});
			},
			//确认时间选择器
			bindDateChange(e) {
				this.formData.log_date = e.detail.value
				this.log_week = this.getWeek(e.detail.value)
			},
			// //---点击实施部位列----
			// showImplement() {
			// 	this.showImplementModal = true
			// },
			// //显示空间选择器
			// showSpacePicker(key) {
			// 	this.implementKey = key
			// 	// this.$refs.mpvueSpaceRef.show()
			// 	if (this.spaceArray.length !== 0) {
			// 		this.$refs.mpvueSpaceRef.show()
			// 	} else {
			// 		uni.showToast({
			// 			title: '该项目未选择户型或户型未定义相关空间',
			// 			mask: false,
			// 			duration: 1500,
			// 			icon: 'none'
			// 		});
			// 	}
			// },
			// ///空间选择器确认
			// onSpaceConfirm(e) {
			// 	this.implementDatas.map((item, index) => {
			// 		if (item.key === this.implementKey) {
			// 			this.implementDatas[index].space_name = e.label
			// 			this.implementDatas[index].spaceId = e.value[0]
			// 			///主要处理：如果之前已经请求过相同部位的数据，就不用在请求
			// 			let hasValue = false
			// 			for (let i = 0; i < this.partArrayList.length; i++) {
			// 				if (this.partArrayList[i].parent_id === e.value[0]) {
			// 					this.partArray = this.partArrayList[i].info
			// 					hasValue = true
			// 				}
			// 			}
			// 			if (!hasValue) {
			// 				this.getPart(e.value[0])
			// 			}
			// 		}
			// 	})
			// },
			// //显示部位选择器
			// showPartPicker(key, spaceId) {
			// 	this.implementKey = key
			// 	//如果空间的数据已经是空了，就不用在请求部位的接口数据了
			// 	if (this.spaceArray.length !== 0) {
			// 		this.$refs.mpvuePartRef.show()
			// 		///主要处理：详情中如果直接点击后面的部位
			// 		let hasValue = false
			// 		for (let i = 0; i < this.partArrayList.length; i++) {
			// 			if (this.partArrayList[i].parent_id === spaceId) {
			// 				this.partArray = this.partArrayList[i].info
			// 				hasValue = true
			// 			}
			// 		}
			// 		if (!hasValue) {
			// 			this.getPart(spaceId)
			// 		}
			// 	} else {
			// 		uni.showToast({
			// 			title: '该项目未选择户型或户型未定义相关空间',
			// 			mask: false,
			// 			duration: 1500,
			// 			icon: 'none'
			// 		});
			// 	}
			// },
			// ///空间选择器确认
			// onPartConfirm(e) {
			// 	this.implementDatas.map((item, index) => {
			// 		if (item.key === this.implementKey) {
			// 			this.implementDatas[index].part_name = e.label
			// 			this.implementDatas[index].partId = e.value[0]
			// 		}
			// 	})
			// },
			// //点击实施部位添加
			// addImplement() {
			// 	this.implementDatas.push({
			// 		key: `NEW_TEMP_IP_${this.implementIndex}`,
			// 		space_name: '',
			// 		spaceId: '',
			// 		part_name: '',
			// 		partId: ''
			// 	})
			// 	this.implementIndex += 1
			// },
			// //实施部位删除
			// removeImplement(e) {
			// 	this.implementDatas = this.implementDatas.filter(item => item.key !== e);
			// },
			// //实施部位确定
			// submitImplement() {
			// 	const listName = []
			// 	const listId = []
			// 	this.implementDatas.map((item, index) => {
			// 		if (item.partId) {
			// 			listName.push(item.space_name + '/' + item.part_name)
			// 			listId.push(item.partId)
			// 		}
			// 	})
			// 	this.project_part_name = listName.join(",")
			// 	this.formData.project_part = listId
			// 	this.showImplementModal = false
			// },
			// //实施部位选择器数据
			// //---1、获取控件
			// getSpace() {
			// 	uni.request({
			// 		url: this.$store.state.baseUrl + '/lwj/app_project_position',
			// 		method: 'POST',
			// 		header: {
			// 			token: this.$store.state.token
			// 		},
			// 		data: {
			// 			hard_id: this.formData.hard_id
			// 		},
			// 		success: res => {
			// 			if (res.data.code === 1) {
			// 				this.spaceArray = res.data.data.info
			// 			} else if (res.data.code === 0) {
			// 				uni.showToast({
			// 					title: res.data.msg,
			// 					mask: false,
			// 					duration: 1500,
			// 					icon: 'none'
			// 				});
			// 			}
			// 		}
			// 	});
			// },
			// //---2、获取部位
			// getPart(currentSpaceId) {
			// 	uni.request({
			// 		url: this.$store.state.baseUrl + '/lwj/app_project_part',
			// 		method: 'POST',
			// 		header: {
			// 			token: this.$store.state.token
			// 		},
			// 		data: {
			// 			hard_id: this.formData.hard_id,
			// 			position_id: currentSpaceId
			// 		},
			// 		success: res => {
			// 			if (res.data.code === 1) {
			// 				this.partArray = res.data.data.info
			// 				this.partArrayList.push({
			// 					parent_id: currentSpaceId,
			// 					info: res.data.data.info
			// 				})
			// 			} else if (res.data.code === 0) {
			// 				uni.showToast({
			// 					title: res.data.msg,
			// 					mask: false,
			// 					duration: 1500,
			// 					icon: 'none'
			// 				});
			// 			}
			// 		}
			// 	});
			// },
			//-----施工项------
			getConstruction() {
				uni.showLoading({
					title: '',
					mask: false
				});
				uni.request({
					url: this.$store.state.baseUrl + '/lwj/app_project_log_process',
					method: 'POST',
					header: {
						token: this.$store.state.token
					},
					data: {},
					success: res => {
						uni.hideLoading()
						if (res.data.code === 1) {
							const list = res.data.data.info
							list.map((item, index) => {
								this.constructionArray.push({
									label: item.label,
									value: [item.value, item.tw_label, item.tw_value, item.type]
								})
							})
						}
					}
				});
			},
			showConstruction() {
				this.$refs.mpvueConstructionRef.show()
				this.isShow = false
			},
			onConstructionConfirm(e) { //施工项确认
				this.isShow = true
				if (this.formData.process_ids.length > 0) {
					if (this.construction.indexOf(e.label) < 0) {
						this.formData.process_ids.push(e.value[0][0]) //去重添加到施工项
						this.construction.push(e.label)
						if (e.label === '其他' || JSON.stringify(this.formData.log_lines).indexOf(e.value[0][1]) > -1) {
							return
						} else {
							this.addAttendance(e.value[0][1], e.value[0][2], e.value[0][3])
						}
						return
					}
				} else {
					this.formData.process_ids.push(e.value[0][0])
					this.construction.push(e.label)
					if (e.label === '其他' || JSON.stringify(this.formData.log_lines).indexOf(e.value[0][1]) > -1) {
						return
					} else {
						this.addAttendance(e.value[0][1], e.value[0][2], e.value[0][3])
					}
				}
			},
			onConstructionCancel(e) { //施工项取消
				if (this.construction.indexOf(e.label) > -1) {
					this.formData.process_ids.splice(this.construction.indexOf(e.label), 1)
					this.construction.splice(this.construction.indexOf(e.label), 1)
					for (var i = 0; i < this.formData.log_lines.length; i++) {
						// 施工项的删除,出勤情况有的话就也删除
						if (this.formData.log_lines[i].type_work === e.value[0][2]) {
							this.formData.log_lines.splice(i, 1)
							this.submitAttendance() //目的是让出勤情况的人数重新计算
						}
					}
				}
				this.isShow = true
			},
			//---点击出勤情况列----
			showAttendance() {
				this.showAttendanceModal = true
			},
			//显示工种类型选择器
			showTypePicker(key) {
				this.attendanceKey = key
				this.$refs.mpvueTypeRef.show()
			},
			///工作类型选择器确认
			onTypeConfirm(e) {
				const principalsArr = this.formData.log_lines.filter((item) => {
					return item.type === 'principals'
				})
				if (e.value[0][1] === 'principals' && principalsArr.length > 0) { //已经存在操作负责人这行了
					uni.showToast({
						title: '操作负责人已经增加,可多选',
						mask: false,
						duration: 1500,
						icon: 'none'
					});
				} else {
					this.formData.log_lines.map((item, index) => {
						if (item.key === this.attendanceKey) { //给当前点击的行赋值
							this.formData.log_lines[index].name = e.label
							this.formData.log_lines[index].type_work = e.value[0][0]
							this.formData.log_lines[index].type = e.value[0][1]
							if (e.value[0][1] === 'principals' && this.personArray.length === 0) {
								this.getPerson()
							}
						}
					})
				}
			},
			//显示负责人选择器
			showPersonPicker(key) {
				this.attendanceKey = key
				this.$refs.mpvuePersonRef.show()
				if (this.personArray.length === 0) {
					this.getPerson()
				}
			},
			///负责人确认
			onPersonConfirm(e) {
				var isHave = false
				this.formData.log_lines.map((item, index) => {
					if (item.key === this.attendanceKey) {
						for (var i = 0; i < this.formData.log_lines[index].principal_info.length; i++) {
							if (this.formData.log_lines[index].principal_info[i].value === e.value[0]) {
								isHave = true
							}
						}
						if (!isHave) {//去重添加负责人列表
							this.formData.log_lines[index].principal_info.push({
								label: e.label,
								value: e.value[0]
							})
						}
					}
				})
			},
			//负责人取消
			onPersonConCancel(e) {
				this.formData.log_lines.map((item, index) => {
					if (item.key === this.attendanceKey) {
						this.formData.log_lines[index].principal_info = this.formData.log_lines[index].principal_info.filter((list) => {
							return e.value[0] !== list.value
						})
					}
				})
			},
			//人数改变获取聚焦
			attendanceInputFocus(key) {
				this.attendanceKey = key
			},
			attendanceInputNumber(e) {
				this.formData.log_lines.map((item, index) => {
					if (item.key === this.attendanceKey) {
						this.formData.log_lines[index].labour_qty = parseInt(e.detail.value)
					}
				})
			},
			//点击出勤情况添加,或者新增页面中默认添加行
			addAttendance(name = '', type_work = null, type = '') {
				this.formData.log_lines.push({
					key: `NEW_TEMP_IP_${this.attendanceIndex}`,
					principal_ids: [], //负责人列表
					labour_qty: null, //数量
					name: name, //工种类型名称
					type_work: type_work, //工种类型
					principal_info: [], //负责人名称
					type: type,
				})
				this.attendanceIndex += 1
			},
			//出勤情况删除
			removeAttendance(e) {
				this.formData.log_lines = this.formData.log_lines.filter(item => item.key !== e);
			},
			//出勤情况确定
			submitAttendance() {
				let number = 0
				let person = []
				let personId = []
				for (let i = 0; i < this.formData.log_lines.length; i++) {
					//普通工人
					if (this.formData.log_lines[i].type === 'workers' && this.formData.log_lines[i].labour_qty >= 0) {
						number += this.formData.log_lines[i].labour_qty
					} else {
						//操作负责人
						number += this.formData.log_lines[i].principal_info.length //总人数也要加上操作负责人的数量
						for (let j = 0; j < this.formData.log_lines[i].principal_info.length; j++) {
							person.push(this.formData.log_lines[i].principal_info[j].label)
							personId.push(this.formData.log_lines[i].principal_info[j].value)
						}
						this.formData.log_lines[i].principal_ids = personId
					}
				}
				this.formData.attendance_situation = '出勤人数' + number + '人,负责人:' + person.join(",")
				this.showAttendanceModal = false
			},
			//出勤情况选择器数据
			//---1、获取工作类型
			getType() {
				uni.request({
					url: this.$store.state.baseUrl + '/lwj/app_project_work_types',
					method: 'POST',
					header: {
						token: this.$store.state.token
					},
					data: {},
					success: res => {
						if (res.data.code === 1) {
							const list = res.data.data.info
							list.map((item, index) => {
								if (item.type === 'principals' && this.isAdd) { //在新增页面，默认让第一行填上负责人的信息
									this.formData.log_lines[0].type_work = item.value
									this.formData.log_lines[0].name = item.label
									this.formData.log_lines[0].type = item.type
								}
								this.typeArray.push({
									label: item.label,
									value: [item.value, item.type]
								})
							})
						}
					}
				});
			},
			//---2、获取负责人列表数据
			getPerson() {
				uni.request({
					url: this.$store.state.baseUrl + '/lwj/app_project_resources',
					method: 'POST',
					header: {
						token: this.$store.state.token
					},
					data: {},
					success: res => {
						this.personArray = res.data.data.info
					}
				});
			},
			//点击突发事件选择器
			showProruptionPicker() {
				this.$refs.mpvueProruptionRef.show()
				this.isShow = false
			},
			//突发事件选择器确认
			onProruptionConfirm(e) {
				this.proruption = e.label
				this.formData.is_emergency = e.value[0]
				this.isShow = true
			},
			onProruptionCancel() {
				this.isShow = true
			},
			submit() {
				//处理出勤情况的空数据
				const log_lines = []
				this.formData.log_lines.map((item, index) => {
					if (item.type === 'principals' && item.principal_ids.length !== 0) {
						log_lines.push(item)
					}
					if (item.type !== 'principals' && item.type !== '') {
						log_lines.push(item)
					}
				})
				this.formData.log_lines = log_lines
				const url = this.isAdd ? '/lwj/app_project_log_create' : '/lwj/app_project_log_write'
				uni.showLoading({
					title: '',
					mask: false
				});
				uni.request({
					url: this.$store.state.baseUrl + url,
					method: 'POST',
					header: {
						token: this.$store.state.token
					},
					data: {
						...this.formData
					},
					success: res => {
						uni.hideLoading()
						if (res.data.code === 1) {
							uni.showToast({
								title: '成功,返回列表',
								mask: false,
								duration: 1500
							});
							this.goIncreaseList()
						} else if (res.data.code === 0) {
							uni.showToast({
								title: res.data.msg,
								mask: false,
								duration: 1500,
								icon: 'none'
							});
						}
					},
				});
			},
			//跳回列表页
			goIncreaseList() {
				setTimeout(() => {
					// const url = this.isFromMain ? './constructionLog' : './constructionLog?id=' + this.formData.hard_id
					// uni.navigateTo({
					// 	url: url,
					// 	success: res => {},
					// 	fail: () => {},
					// 	complete: () => {}
					// })
					this.$eventBus.$emit('constructionLogEditExecute')
					uni.navigateBack({
						delta: 1
					})
				}, 1500)
			}
		}
	}
</script>

<style scoped>
	.edit-content {
		background-color: #FFFFFF;
		padding-left: 20upx;
	}

	.right-text,
	picker {
		margin-right: 25upx;
		text-align: right;
	}

	textarea {
		height: 150upx;
	}

	.task-comment-popup-title {
		text-align: center;
	}

	.list-row {
		display: flex;
		flex-direction: row;
	}

	.implement-text {
		border: 1upx solid #00BFFF;
		margin-right: 20upx;
	}

	.text {
		height: auto;
		width: 10upx;
		margin-bottom: 10upx;
	}

	.min-picker {
		border: 1px solid #008FF3;
		flex-grow: 1
	}

	.content {
		margin-top: 10upx;
		background-color: #FFFFFF;
		padding-left: 0;

	}

	.picker {
		flex: 2;
	}

	.btn-primary {
		width: 600upx;
		margin: 20upx 0 20upx 75upx;
	}
</style>
